package cn.edu.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Davey chan
 */
@Component
@Aspect
public class ProjectAdvice {
//匹配业务层的所有接口
    @Pointcut("execution(* cn.edu.service.*Service.*(..))")//括号里的..表示任意参数
    private void servicept(){}

    @Around("servicept()")
    public Object runSpeed(ProceedingJoinPoint pjp) throws Throwable{
//        获取执行签名的信息
        Signature signature = pjp.getSignature();
        String className=signature.getDeclaringTypeName();
        String methodName=signature.getName();
        Long start=System.currentTimeMillis();
        Object ret=null;
        for (int i = 0; i <10000 ; i++) {
             ret=pjp.proceed();
        }
      Long end=System.currentTimeMillis();
        System.out.println("万次执行："+className+"."+methodName+"-->"+(end-start)+"ms");
         return ret;
    }
}
